/*
 * Copyright 2009 BioTeam Inc
 * 
 * Licensed under License GNU LESSER GENERAL PUBLIC LICENSE version 3.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.gnu.org/copyleft/lesser.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package net.bioteam.appweb.submit;

import static javax.persistence.GenerationType.TABLE;
import static javax.persistence.TemporalType.TIMESTAMP;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.Transient;


@Entity
@Table(name = "UNFINISHEDJOB")
@NamedQuery(name="allunfinishedjobs", query = "select job from UnfinishedJob  job ")
public class UnfinishedJob {
	@Transient
    public String getWorkdirName()
	{
		return rs.getWorkdirName();
	}

	public String getRemoteJobId()
	{
		return rs.getRemoteJobId();
	}

	public void setRemoteJobId(String remoteJobId)
	{
		rs.setRemoteJobId(remoteJobId);
	}

	/**
     *
     */
    private static final long serialVersionUID = 1L;
    protected RunStatus rs;

    public int getTrials()
	{
		return rs.getTrials();
	}

	public void setTrials(int trials)
	{
		rs.setTrials(trials);
	}

	public String getNote()
	{
		return rs.getNote();
	}

	public void setNote(String note)
	{
		rs.setNote(note);
	}

	public long getClusterid()
	{
		return rs.getClusterid();
	}

	public Date getPreSubmitTime()
	{
		return rs.getPreSubmitTime();
	}

	public void setClusterid(long clusterid)
	{
		rs.setClusterid(clusterid);
	}

	public void setPreSubmitTime(Date preSubmitTime)
	{
		rs.setPreSubmitTime(preSubmitTime);
	}

	public String getEmail() {
		return rs.getEmail();
	}

	public void setEmail(String email) {
		rs.setEmail(email);
	}

	public UnfinishedJob() {
        rs = new RunStatus();
    }

    public UnfinishedJob(RunStatus rs) {
        this.rs = rs;
    }

    @Transient
    public RunStatus getRunStatus() {
        return rs;
    }

    @Column(name = "CMDLINE")
    public String getCmdline() {
        return rs.getCmdline();
    }

    @Column(name = "STATUS")
    public RunStatusCode getCode() {
        return rs.getCode();
    }

    @Column(name = "EXITVALUE")
    public int getExitValue() {
        return rs.getExitValue();
    }

    @Column(name = "FINISHTIME")
    @Temporal(TIMESTAMP)
    public Date getFinishedTime() {
        return rs.getFinishedTime();
    }

    @Id
    @Column(name = "ID", updatable = false)
    @GeneratedValue(strategy = TABLE, generator = "jobhistory_seq")
    @TableGenerator(name = "jobhistory_seq", table = "SEQUENCES", pkColumnName = "NAME", valueColumnName = "SEQVALUE", pkColumnValue = "job")
    public long getId() {
        return rs.getId();
    }

    public String getJobid() {
        return rs.getJobid();
    }

    @Column(name = "PROGRAMNAME")
    public String getProgramName() {
        return rs.getProgramName();
    }

    @Column(name = "SUBMITTIME")
    @Temporal(TIMESTAMP)
    public Date getSubmittedTime() {
        return rs.getSubmittedTime();
    }

    @Column(name = "USERID")
    public String getUsername() {
        return rs.getUsername();
    }

    @Column(name = "WORKDIR")
    public String getWorkdir() {
        return rs.getWorkdir();
    }

    @Transient
    public boolean isRunning() {
        return rs.isRunning();
    }

    public void setCmdline(String cmdline) {
        rs.setCmdline(cmdline);
    }

    public void setCode(RunStatusCode code) {
        rs.setCode(code);
    }

    public void setExitValue(int exitValue) {
        rs.setExitValue(exitValue);
    }

    public void setFinishedTime(Date finishedTime) {
        rs.setFinishedTime(finishedTime);
    }

    public void setId(long id) {
        rs.setId(id);
    }

    public void setJobid(String jobid) {
        rs.setJobid(jobid);
    }

    public void setProgramName(String programName) {
        rs.setProgramName(programName);
    }

    public void setSubmittedTime(Date submittedTime) {
        rs.setSubmittedTime(submittedTime);
    }

    public void setUsername(String username) {
        rs.setUsername(username);
    }

    public void setWorkdir(String workdir) {
        rs.setWorkdir(workdir);
    }
    @Transient
    public boolean isRemoteJob()
    {
    	return getClusterid() != RunStatus.LOCAL_CLUSTER;
    }
}
